<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/25
 * Time: 10:15
 */
namespace common\sources\write\taskcommod;

use common\models\craftsman\TaskCommod;
use Yii;
class TaskCommodAccess implements ITaskCommodAccess
{
    //添加店铺信息
    public function addTask($data)
    {
        return Yii::$app->db->createCommand()->insert('task_commod', [
            'bus_id' => $data['bus_id'],
            'plat_type' => $data['plat_type'],
            'shop_id' => $data['shop_id'],
            'shop_name' => $data['shop_name'],
            'task_type' => $data['task_type'],
            'port_type' => $data['port_type'],
            'commod_link' => $data['commod_link'],
            'title' => $data['title'],
            'main_url1' => $data['main_url1'],
            'main_url2' => $data['main_url2'],
            'qr_code_url' => $data['qr_code_url'],
            'colour' => $data['colour'],
            'size' => $data['size'],
            'num' => $data['num'],
            'range_price' => $data['range_price'],
            'ship_addr' => $data['ship_addr'],
            'task_num' => $data['task_num'],
            'prompt' => $data['prompt'],
            'bus_phone' => $data['bus_phone'],
            'task_id' => $data['task_id'],
            'com_amount' => $data['com_amount'],
            'margin' => $data['margin'],
            'pay_task_amount' => $data['pay_task_amount'],
            'item_commisse' => $data['item_commisse'],
            'com_task_commisse' => $data['com_task_commisse'],
            'buy_get_commisse' => $data['buy_get_commisse'],
            'public_task_status' => $data['public_task_status'],
            'price' => $data['price'],
            'create_time' => time()
        ])->execute();
    }
    //修改店铺任务信息
    public function modifyTask($data)
    {
        $sql = 'UPDATE ' . TaskCommod::tableName() . ' SET bus_id = :bus_id,plat_type = :plat_type,shop_id = :shop_id,shop_name = :shop_name,task_type = :task_type,port_type = :port_type,
        commod_link = :commod_link,title = :title,main_url1 = :main_url1,
        main_url2 = :main_url2,qr_code_url = :qr_code_url,colour = :colour,size = :size,num = :num,range_price = :range_price,ship_addr = :ship_addr,task_num = :task_num,
        prompt = :prompt,bus_phone = :bus_phone,com_amount = :com_amount,margin = :margin,pay_task_amount = :pay_task_amount,item_commisse = :item_commisse,
        com_task_commisse = :com_task_commisse,buy_get_commisse = :buy_get_commisse,public_task_status = :public_task_status,price = :price,
        update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':bus_id' => $data['bus_id'],
                ':plat_type' => $data['plat_type'],
                ':shop_id' => $data['shop_id'],
                ':shop_name' => $data['shop_name'],
                ':task_type' => $data['task_type'],
                ':port_type' => $data['port_type'],
                ':commod_link' => $data['commod_link'],
                ':title' => $data['title'],
                ':main_url1' => $data['main_url1'],
                ':main_url2' => $data['main_url2'],
                ':qr_code_url' => $data['qr_code_url'],
                ':colour' => $data['colour'],
                ':size' => $data['size'],
                ':num' => $data['num'],
                ':range_price' => $data['range_price'],
                ':ship_addr' => $data['ship_addr'],
                ':task_num' => $data['task_num'],
                ':prompt' => $data['prompt'],
                ':bus_phone' => $data['bus_phone'],
                ':com_amount' => $data['com_amount'],
                ':margin' => $data['margin'],
                ':pay_task_amount' => $data['pay_task_amount'],
                ':item_commisse' => $data['item_commisse'],
                ':com_task_commisse' => $data['com_task_commisse'],
                ':buy_get_commisse' => $data['buy_get_commisse'],
                ':public_task_status' => $data['public_task_status'],
                ':price' => $data['price'],
                ':update_time' => time(),
                ':id' => $data['task_commod_id']
            ])->execute();
    }

    public function modiyTaskCommod($data)
    {
        $sql = 'UPDATE ' . TaskCommod::tableName() . ' SET bus_id = :bus_id,commod_link = :commod_link,title = :title,main_url1 = :main_url1,
        main_url2 = :main_url2,qr_code_url = :qr_code_url,colour = :colour,size = :size,num = :num,range_price = :range_price,ship_addr = :ship_addr,task_num = :task_num,
        keywords = :keywords,prompt = :prompt,bus_phone = :bus_phone,task_id = :task_id,com_amount = :com_amount,margin = :margin,pay_task_amount = :pay_task_amount,item_commisse = :item_commisse,
        com_task_commisse = :com_task_commisse,buy_get_commisse = :buy_get_commisse,public_task_status = :public_task_status,price = :price,
        update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':bus_id' => $data['bus_id'],
                ':commod_link' => $data['commod_link'],
                ':title' => $data['title'],
                ':main_url1' => $data['main_url1'],
                ':main_url2' => $data['main_url2'],
                ':qr_code_url' => $data['qr_code_url'],
                ':colour' => $data['colour'],
                ':size' => $data['size'],
                ':num' => $data['num'],
                ':range_price' => $data['range_price'],
                ':ship_addr' => $data['ship_addr'],
                ':task_num' => $data['task_num'],
                ':keywords' => $data['keywords'],
                ':prompt' => $data['prompt'],
                ':bus_phone' => $data['bus_phone'],
                ':task_id' => $data['task_id'],
                ':com_amount' => $data['com_amount'],
                ':margin' => $data['margin'],
                ':pay_task_amount' => $data['pay_task_amount'],
                ':item_commisse' => $data['item_commisse'],
                ':com_task_commisse' => $data['com_task_commisse'],
                ':buy_get_commisse' => $data['buy_get_commisse'],
                ':public_task_status' => $data['public_task_status'],
                ':price' => $data['price'],
                ':update_time' => time(),
                ':id' => $data['task_commod_id']
            ])->execute();
    }
    public function addTaskCommod($data)
    {
       return Yii::$app->db->createCommand()->insert('task_commod', [
            'bus_id' => $data['bus_id'],
            'plat_type' => $data['plat_type'],
            'shop_id' => $data['shop_id'],
            'shop_name' => $data['shop_name'],
            'task_type' => $data['task_type'],
            'port_type' => $data['port_type'],
            'commod_link' => $data['commod_link'],
            'title' => $data['title'],
            'main_url1' => $data['main_url1'],
            'main_url2' => $data['main_url2'],
            'qr_code_url' => $data['qr_code_url'],
            'colour' => $data['colour'],
            'size' => $data['size'],
            'price' => $data['price'],
            'num' => $data['num'],
            'range_price' => $data['range_price'],
            'ship_addr' => $data['ship_addr'],
            'task_num' => $data['task_num'],
            'keywords' => $data['keywords'],
            'prompt' => $data['prompt'],
            'bus_phone' => $data['bus_phone'],
            'task_id' => $data['task_id'],
            'com_amount' => $data['com_amount'],
            'margin' => $data['margin'],
            'pay_task_amount' => $data['pay_task_amount'],
            'item_commisse' => $data['item_commisse'],
            'com_task_commisse' => $data['com_task_commisse'],
            'buy_get_commisse' => $data['buy_get_commisse'],
            'create_time' => time()
        ])->execute();
    }
    public function modifyTaskCommod($data)
    {
        $sql = 'UPDATE ' . TaskCommod::tableName() . ' SET return_type = :return_type,freight_deposit = :freight_deposit,avail_task_num = :avail_task_num,pay_task_commisse = :pay_task_commisse,
        pay_task_amount = :pay_task_amount,total_amount = :total_amount,
        service_amount = :service_amount,public_task_status = :public_task_status,task_classify = :task_classify,item_task_amount = :item_task_amount,surplus_task_num = :surplus_task_num,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':return_type' => $data['return_type'],
                ':freight_deposit' => $data['freight_deposit'],
                ':avail_task_num' => $data['avail_task_num'],
                ':pay_task_commisse' => $data['pay_task_commisse'],
                ':pay_task_amount' => $data['pay_task_amount'],
                ':total_amount' => $data['total_amount'],
                ':service_amount' => $data['service_amount'],
                ':public_task_status' => $data['public_task_status'],
                ':task_classify' => $data['task_classify'],
                ':item_task_amount' => $data['item_task_amount'],
                ':surplus_task_num' => $data['surplus_task_num'],
                ':update_time' => time(),
                ':id' => $data['id']
            ])->execute();
    }
    //支付任务订单
    public function payTaskCommod($data)
    {
        $sql = 'UPDATE ' . TaskCommod::tableName() . ' SET public_task_status = :public_task_status,task_status = :task_status,pay_time = :pay_time,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':public_task_status' => $data['public_task_status'],
                ':task_status' => $data['task_status'],
                ':update_time' => time(),
                ':pay_time' => time(),
                ':id' => $data['id']
            ])->execute();
    }
    public function modifyTaskShopImage($data)
    {
        $sql = 'UPDATE ' . TaskCommod::tableName() . ' SET is_task_image = :is_task_image,img_praise_type = :img_praise_type,
        img_prase_type_pepper = :img_prase_type_pepper,task_img_pepper = :task_img_pepper,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':is_task_image' => $data['is_task_image'],
                ':img_praise_type' => $data['img_praise_type'],
                ':img_prase_type_pepper' => $data['parase_type_pepper'],
                ':task_img_pepper' => $data['task_img_pepper'],
                ':update_time' => time(),
                ':id' => $data['id']
            ])->execute();
    }
    //任务状态改变
    public function modifyTaskStatus($data)
    {
        $sql = 'UPDATE ' . TaskCommod::tableName() . ' SET task_status = :task_status,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':task_status' => $data['task_status'],
                ':update_time' => time(),
                ':id' => $data['task_commod_id']
            ])->execute();
    }
}